/**
 * Created by reeves on 2017/1/25.
 */
Meteor.publish('posts', function (options) {
    check(options, {
        sort: Object,
        limit: Number
    });
    return Posts.find({}, options);
});

// 收藏列表
Meteor.publish('starPosts', function (options) {
    check(options, {
        in: Array
    });

    return Posts.find({_id: {$in: options.in}}, {sort: {time: -1}});
});

// 搜索
Meteor.publish('search', function (keywords, options) {
    check(keywords, String);
    check(options, {
        sort: Object
    });
    var pattern = new RegExp("^.*" + keywords + ".*$", "i");
    return Posts.find({title: pattern}, options);
});

// 发布单个用户收藏记录
Meteor.publish('userStars', function (uid) {
    check(uid, String);
    return Star.find({userId: uid});
});

// 发布单个帖子信息
Meteor.publish('singlePost', function (id) {
    check(id, String);
    return Posts.find(id);
});

// 发布特定分类下的帖子
Meteor.publish('categoryPost', function (categoryName) {
    check(categoryName, String);
    return Posts.find({category: categoryName});
});

// 发布评论信息
Meteor.publish('comments', function (postId) {
    check(postId, String);
    return Comments.find({postId: postId});
});

// 发布通知信息
Meteor.publish('notifications', function () {
    return Notifications.find();
});

// 发布分类信息
Meteor.publish('category', function () {
    var result = []; // [{name:"",new:6}]

    return Category.find();
});

// 发布反馈信息
Meteor.publish('feedback', function () {
    return Feedback.find();
});